from PIL import Image

def resize_image(image:Image, max_res=256):
    # resize too large image
    higher_res = max(image.size)
    if higher_res >= max_res:
        scale = higher_res / max_res
        image = image.resize((int(image.size[0] / scale), int(image.size[1] / scale)), Image.Resampling.NEAREST)
    return image